using Furion.DataEncryption;
namespace Tool
{
    /// <summary>
    /// 加密解密类扩展
    /// 虽然Furion已有对应扩展，但是要分别引用不同命名空间，比较麻烦，所以外面再套了一层。
    /// </summary>
    public static partial class ExtensionHelper
    {
        /// <summary>
        /// 字符串的 Md5
        /// </summary>
        /// <param name="str"></param>
        /// <returns>string</returns>
        public static string ToMd5(this string str)
        {
            // return Md5Helper.Md5(str);
            return MD5Encryption.Encrypt(str);
        }

        /// <summary>
        /// 字符串的 ToPBKDF2
        /// </summary>
        /// <param name="str"></param>
        /// <returns>string</returns>
        public static string ToPBKDF2(this string str)
        {
            return PBKDF2Encryption.Encrypt(str);
        }
        /// <summary>
        /// 加密比较 ToPBKDF2
        /// </summary>
        /// <param name="inputText">输入文本</param>
        /// <param name="encryptText">加密文本</param>
        /// <returns>string</returns>
        public static bool ToPBKDF2Compare2(this string inputText,string encryptText)
        {
            return PBKDF2Encryption.Compare(inputText, encryptText);
        }
        ///// <summary>
        ///// 字符串的Hash
        ///// </summary>
        ///// <param name="str">需要计算hash的字符串</param>
        ///// <returns>string</returns>
        //public static string ToHash(this string str)
        //{
        //    return HashHelper.Hash(str);
        //}

        #region AES
        private static string AesDefaultKey = "#@iST~&i+DaFGdd^544#$d^++2@#6@id";
        /// <summary>
        /// 字符串Aes 加密
        /// </summary>
        /// <param name="text">需要加密的字符串</param>
        /// <returns>string</returns>
        public static string ToAESEncrypt(this string text)
        {
            return AESEncryption.Encrypt(text, AesDefaultKey);
        }
        /// <summary>
        /// 字符串Aes 解密
        /// </summary>
        /// <param name="text"></param>
        /// <returns>string</returns>
        public static string ToAESDecrypt(this string text)
        {
            return AESEncryption.Decrypt(text, AesDefaultKey);
        }

        /// <summary>
        /// 字符串Aes 加密
        /// </summary>
        /// <param name="text">需要加密的字符串</param>
        /// <param name="skey">密钥（长度为32的2次方数）</param>
        /// <returns>string</returns>
        public static string ToAESEncrypt(this string text, string skey)
        {
            if (string.IsNullOrWhiteSpace(skey)) skey = AesDefaultKey;
            return AESEncryption.Encrypt(text, skey);
        }
        /// <summary>
        /// 字符串Aes 解密
        /// </summary>
        /// <param name="text"></param>
        /// <param name="skey">密钥（长度为32的2次方数）</param>
        /// <returns>string</returns>
        public static string ToAESDecrypt(this string text, string skey)
        {
            //return AesHelper.Decrypt(data);
            if (string.IsNullOrWhiteSpace(skey)) skey = AesDefaultKey;
            return AESEncryption.Decrypt(text, skey);
        }
        #endregion

        #region DESC
        private static string DescDefaultKey = "#@iST~&i+DaFGdd^544#$d^++2@#6@id";
        /// <summary>
        /// 字符串Aes 加密
        /// </summary>
        /// <param name="text">需要加密的字符串</param>
        /// <returns>string</returns>
        public static string ToDESCEncrypt(this string text)
        {
            return DESCEncryption.Encrypt(text, DescDefaultKey);
        }
        /// <summary>
        /// 字符串Aes 解密
        /// </summary>
        /// <param name="text"></param>
        /// <returns>string</returns>
        public static string ToDESCDecrypt(this string text)
        {
            return DESCEncryption.Decrypt(text, DescDefaultKey);
        }

        /// <summary>
        /// 字符串Aes 加密
        /// </summary>
        /// <param name="text">需要加密的字符串</param>
        /// <param name="skey">密钥（长度为32的2次方数）</param>
        /// <returns>string</returns>
        public static string ToDESCEncrypt(this string text, string skey)
        {
            if (string.IsNullOrWhiteSpace(skey)) skey = DescDefaultKey;
            return DESCEncryption.Encrypt(text, skey);
        }

        /// <summary>
        /// 字符串Aes 解密
        /// </summary>
        /// <param name="text"></param>
        /// <param name="skey">密钥（长度为32的2次方数）</param>
        /// <returns>string</returns>
        public static string ToDESCDecrypt(this string text, string skey)
        {
            if (string.IsNullOrWhiteSpace(skey)) skey = DescDefaultKey;
            return DESCEncryption.Decrypt(text, skey);
        }
        #endregion
    }
}
